<template>
	<uni-table stripe v-bind="$attrs">
		<uni-tr v-if="haeder" class="uni-table-haeder">
			<uni-th v-for="item in columns" :key="item.label" v-bind="item">{{item.label}}</uni-th>
		</uni-tr>
		<uni-tr v-for="(row, rowIndex) in data" :key="rowIndex" @click.native="$emit('row-click',{row})">
			<uni-td v-for="(column,colIndex) in columns" :key="colIndex" v-bind="{...column,...row}">
				<slot :name="column.prop || 'default'" v-bind="{row, column, rowIndex}">
					{{column?.formatter?.(row, column, row[column.prop], rowIndex) || row[column.prop]}}
				</slot>
			</uni-td>
		</uni-tr>
	</uni-table>
</template>

<script setup>
	/***
	 * props
	 * @property {Array} [columns = []]  表格列定义，对象属性参数完全继承 uni-th
	 * @property {Array} [data = []]  表格数据
	 * @property {Boolean} [haeder = true]  是否显示表格头部
	 * 设备 style="max-height:600rpx" 样式即可开启表头固定
	 */
	const props = defineProps({
		data: {
			type: Array,
			default: () => []
		},
		columns: {
			type: Array,
			default: () => []
		},
		haeder: {
			type: Boolean,
			default: true
		},
	});
</script>

<style lang="scss" scoped>
	.uni-table-haeder {
		position: sticky;
		left: 0;
		top: 0;
	}
</style>